package com.software.graduationproject.modules.sys.web;

import com.baomidou.mybatisplus.core.metadata.Page;

import com.software.graduationproject.commons.util.Result;
import com.software.graduationproject.commons.util.Results;
import com.software.graduationproject.modules.sys.entity.SysUserRole;
import com.software.graduationproject.modules.sys.object.SysUserRoleVo;
import com.software.graduationproject.modules.sys.service.SysUserRoleService;
import com.software.graduationproject.modules.sys.object.SysUserRoleCreateQo;
import com.software.graduationproject.modules.sys.object.SysUserRoleUpdateQo;

import com.v2coding.validate.CreateGroup;
import com.v2coding.validate.UpdateGroup;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * SysUserRoleController : 客户用户
 * ---------------------------------------------------------------------------------------------------------------------
 */
@Validated
@RestController
@RequestMapping("/Sys/SysUserRole")
@Api(value = "API - 客户用户", tags = {"客户用户接口"})
public class SysUserRoleController {

    @Autowired
    private SysUserRoleService sysUserRoleService;

//    @PostMapping("/create")
//    @ApiOperation("新增客户用户")
//    public Result createQo(@RequestBody @Validated(CreateGroup.class) SysUserRoleCreateQo qo) {
//        sysUserRoleService.createQo(qo);
//        return Results.success();
//    }
//
//    @PostMapping("/update")
//    @ApiOperation("修改客户用户")
//    public Result updateQo(@RequestBody @Validated(UpdateGroup.class) SysUserRoleUpdateQo qo) {
//        sysUserRoleService.updateQo(qo);
//        return Results.success();
//    }
//
//    @PostMapping("/delete")
//    @ApiOperation("删除客户用户")
//    public Result delete(@RequestBody Long id) {
//        sysUserRoleService.delete(id);
//        return Results.success();
//    }
//
//    @PostMapping("/deleteList")
//    @ApiOperation("批量删除客户用户")
//    public Result deleteList(@RequestBody Long []ids) {
//        sysUserRoleService.deleteList(ids);
//        return Results.success();
//    }
//
//    @GetMapping("/select")
//    @ApiOperation("查询客户用户详情")
//    public Result<SysUserRoleVo> selectVo(Long id) {
//        SysUserRoleVo sysUserRoleVo = sysUserRoleService.selectVo(id);
//        return Results.success(sysUserRoleVo);
//    }

    @GetMapping("/selectList")
    @ApiOperation("查询客户用户列表")
    public Result<List<SysUserRoleVo>> selectListVo() {
        List<SysUserRoleVo> sysUserRoleVoList = sysUserRoleService.selectListVo();
        return Results.success(sysUserRoleVoList);
    }

    @GetMapping("/selectPage")
    @ApiOperation("查询客户用户分页")
    public Result<Page<SysUserRoleVo>> selectPageVo() {
        Page<SysUserRoleVo> sysUserRoleVoPage = sysUserRoleService.selectPageVo();
        return Results.success(sysUserRoleVoPage);
    }

//    @GetMapping("/export")
//    @ApiOperation("导出客户用户")
//    @SelectParam({"sort.id=desc"})
//    @ApiImplicitParams({ //
//            @ApiImplicitParam(name = "select", value = "查询条件", required = false, dataTypeClass = String.class, paramType = "query"),//
//            @ApiImplicitParam(name = "columns", value = "导出列", required = true, dataTypeClass = String.class, paramType = "query"),//
//    })
//    public void export(@ApiIgnore Select select,@RequestParam(defaultValue = "导出.xls") String title, String columns, String headers) {
//        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletResponse response = requestAttributes.getResponse();
//        // @formatter:off
//        Excels.ExportParams params = new Excels.ExportParams()
//                .setList(sysUserRoleService.selectList(select, SysUserRoleVo.class))
//                .setClazz(SysUserRole.class)
//                .setColumns(columns)
//                .setHeaders(headers);
//        // @formatter:on
//        Excels.export(params, response);
//    }

}
